import {
  HTTP
} from './http-prosime.js'
class KeywordMode extends HTTP {
  key = 'queryWord'
  maxLength = 10
  getHistory() {
    const words = wx.getStorageSync(this.key)
    if (!words) {
      return []
    }
    return words
  }

  getHot(index) {
    return this.request({
      url: 'musicRankingsDetails?type='+index
    })

  }

  addToHistory(keyword) {
    let words = this.getHistory()
    const has = words.includes(keyword)

    if (!has) {
      if (words.length >= this.maxLength) {
        words.pop()
      }

      words.unshift(keyword)
      wx.setStorageSync(this.key, words)
    }
  }
}

export {
  KeywordMode
}